package service

import (
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
	sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111"
)

func SendMessage(phone string, vcode string, templateId string) error {
	credential := common.NewCredential(
		"AKIDiIf5Wq9JEwQfhXJqR4atxnQnwQjpdHnX",
		"BHZ7aqvpV5au2wd6QXQ52nGcwBFF5i7X",
	)

	cpf := profile.NewClientProfile()
	cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com"
	client, _ := sms.NewClient(credential, "ap-nanjing", cpf)
	request := sms.NewSendSmsRequest()
	request.PhoneNumberSet = common.StringPtrs([]string{ phone })
	request.SmsSdkAppId = common.StringPtr("1400765333")
	request.SignName = common.StringPtr("厚雪")

	if templateId == "1606145" {
		request.TemplateId = common.StringPtr("1606145")
		request.TemplateParamSet = common.StringPtrs([]string{ vcode, "1" })
	} else if templateId == "1606146" {
		request.TemplateId = common.StringPtr("1606146")
		request.TemplateParamSet = common.StringPtrs([]string{ vcode })
	}

	_, err := client.SendSms(request)
	if _, ok := err.(*errors.TencentCloudSDKError); ok {
		return err
	}
	if err != nil {
		panic(err)
		return err
	}

	return nil
} 